---
description: "Reference for Nitric's v0 Go library - Register a single handler for all HTTP Methods (GET, POST, PUT, DELETE, PATCH) on the route."
---

# Go - Api.Route.All()

Register a single handler for all HTTP Methods (GET, POST, PUT, DELETE, PATCH) on the route.

```go
import (
  "fmt"

  "github.com/nitrictech/go-sdk/faas"
  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  customersRoute, err := nitric.NewApi("public").NewRoute("/customers")
  if err != nil {
    return
  }

  customersRoute.All(func(ctx *faas.HttpContext, next faas.HttpHandler) (*faas.HttpContext, error) {
    ctx.Response.Body = []byte("")
    return next(ctx)
  })

  nitric.Run()
}
```

## Parameters

<Properties>
  <Property name="middleware" required type="HttpMiddleware">
    The middleware function to use as the handler for HTTP requests. If you want
    to compose more than one middleware use `faas.ComposeHttpMiddleware`.
  </Property>
</Properties>

### Method options

<Properties>
  <Property name="WithNoMethodSecurity()" type="MethodOption">
    Sets a base path for all the routes in the API.
  </Property>
  <Property name="WithMethodSecurity()" type="MethodOption">
    Overrides a security rule from API defined JWT rules.
    <Properties nested>
      <Property name="name" required type="string">
        The name of the security rule.
      </Property>
      <Property name="scopes" required type="[]string">
        The scopes of the security rule.
      </Property>
    </Properties>
  </Property>
</Properties>

### Notes

When using the `all()` method to register a single function as the handler for all HTTP methods, none of the other methods should be defined on that route.

```go
import (
  "fmt"

  "github.com/nitrictech/go-sdk/faas"
  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  customersRoute, err := nitric.NewApi("public").NewRoute("/customers")
  if err != nil {
    return
  }

  customersRoute.All(func(ctx *faas.HttpContext, next faas.HttpHandler) (*faas.HttpContext, error) {
    /* handle all requests */
    return next(ctx)
  })

  customersRoute.Get(func(ctx *faas.HttpContext, next faas.HttpHandler) (*faas.HttpContext, error) {
     /* this handler won't work */
  })

  nitric.Run()
}
```

## Examples

### Register a method handler function

```go
import (
  "fmt"

  "github.com/nitrictech/go-sdk/faas"
  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  customersRoute, err := nitric.NewApi("public").NewRoute("/customers")
  if err != nil {
    return
  }

  customersRoute.All(func(ctx *faas.HttpContext, next faas.HttpHandler) (*faas.HttpContext, error) {
    ctx.Response.Body = []byte("")
    return next(ctx)
  })

  nitric.Run()
}
```

### Chain services as a single method handler

When multiple services are provided they will be called as a chain. If one succeeds, it will move on to the next. This allows middleware to be composed into more complex handlers.

```go
import (
  "fmt"

  "github.com/nitrictech/go-sdk/faas"
  "github.com/nitrictech/go-sdk/nitric"
)

func authMiddleware(ctx *faas.HttpContext, next faas.HttpHandler) (*faas.HttpContext, error) {
  // Perform auth validation
  return next(ctx)
}

func handleRequest(ctx *faas.HttpContext, next faas.HttpHandler) (*faas.HttpContext, error) {
  name := ctx.Request.PathParams()["name"]
  ctx.Response.Body = []byte("Hello " + name)
  return next(ctx)
}

func main() {
  customersRoute, err := nitric.NewApi("private").NewRoute("/customers")
  if err != nil {
    return
  }

  customersRoute.All(faas.ComposeHttpMiddleware(authMiddleware, handleRequest))

  nitric.Run()
}
```

### Access the request body

For methods that include a request body, such as `POST` and `PUT`, you can access the body from the `ctx.Request.Data()` object.

```go
import (
  "fmt"

  "github.com/nitrictech/go-sdk/faas"
  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  customersRoute, err := nitric.NewApi("public").NewRoute("/customers")
  if err != nil {
    return
  }

  customersRoute.All(func(ctx *faas.HttpContext, next faas.HttpHandler) (*faas.HttpContext, error) {
    data := ctx.Request.Data()

    ctx.Response.Body = data

    return next(ctx)
  })

  nitric.Run()
}
```
